home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / network / file-tra / fsp-2.7 / fsp-2 / fsp / common / strdup.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-08-02  |  578 b   |  40 lines

  1. #include "tweak.h"
  2.  
  3. char *strstr (char *str, char *sub)
  4. {
  5.     int sublen;
  6.  
  7.     sublen = strlen (sub);
  8.     while (*str)
  9.     {
  10.         if (! strncmp (str, sub, sublen))
  11.             return (str);
  12.         str++;
  13.     }
  14.     return ( (char*) 0 );
  15. }
  16.  
  17. #ifdef NEED_STRDUP
  18.  
  19. #include <stdio.h>
  20. #include "my-string.h"
  21.  
  22. char *strdup PROTO1(char *, str)
  23. {
  24.   char *nstr;
  25.  
  26.   if (str == (char*)0) return str;
  27.  
  28.   nstr = (char*)malloc((unsigned int)(strlen(str) + 1));
  29.  
  30.   if (nstr == (char*)0) {
  31.     fprintf(stderr, "strdup(): not enough memory to duplicate `%s'\n", str);
  32.     exit(1);
  33.   }
  34.  
  35.   strcpy(nstr, str);
  36.  
  37.   return nstr;
  38. }
  39. #endif
  40.